package 青岛大学;

import com.alibaba.excel.EasyExcel;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import 武汉大学.WhuBean;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class QDu {
    public static void main(String[] args) throws IOException {
        QDuBean qDuBean = null;
        List<QDuBean> qDuBeans = new ArrayList<>();
        String Url = "http://ee.qdu.edu.cn/rcdw/szdw/djydqx.htm";
        String a_p = null;
        Connection connect = Jsoup.connect(Url);
        Document post = connect.post();
        Element element = post.getElementsByClass("content-r").get(0);
        for (Element a : element.getElementsByTag("li")) {
            qDuBean=new QDuBean();
            String attr = a.getElementsByTag("a").attr("href");
            if (attr.length() < 16) {
                continue;
            } else {
                a_p = attr.substring(6, attr.length());
            }
//            System.out.println(a_p);
            Connection connect1 = Jsoup.connect("http://ee.qdu.edu.cn/" + a_p);
            Document post1 = connect1.post();
            for (Element elementsByClass : post1.getElementsByClass("art-tit-box clear")) {
                String text = elementsByClass.getElementsByTag("p").text();
                qDuBean.setT_name(text);
//                System.out.println(text);//name
                qDuBeans.add(qDuBean);
            }
            for (Element elementsByClass : post1.getElementsByClass("art-con")) {
                for (Element span : elementsByClass.getElementsByTag("span")) {
                    if (span.text().length()<2){
                        continue;
                    }else {
                        qDuBean.setInfo(span.text());

                    }
//                    System.out.println(span.text());
                }
            }
        }
        EasyExcel.write("src/QDu.xlsx", QDuBean.class).sheet("user").doWrite(qDuBeans);

    }
}
